package com.wanxi.servlet.company;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.CompanyService;
import com.wanxi.service.Impl.CompanyServiceImpl;
import com.wanxi.vo.CompanyVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/admin/company/update")
public class UpdateCompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码处理、传输格式处理
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json");
//        获取前端传来的值
        String logoLocation=req.getParameter("logoLocation");
        String chineseName=req.getParameter("chineseName");
        String englishName=req.getParameter("englishName");
        String introduction=req.getParameter("introduction");
        String qqID=req.getParameter("qqID");
        String wbID=req.getParameter("wbID");
        String telephone=req.getParameter("telephone");
        String email=req.getParameter("email");
        String weChat=req.getParameter("weChat");
        String address=req.getParameter("address");
        String remark=req.getParameter("remark");
//        调用service处理
        CompanyVO companyVO= CompanyVO.builder()
                .logoLocation(logoLocation)
                .chineseName(chineseName)
                .englishName(englishName)
                .introduction(introduction)
                .qqID(qqID)
                .wbID(wbID)
                .telephone(telephone)
                .email(email)
                .weChat(weChat)
                .address(address)
                .remark(remark).build();
        CompanyService companyService=new CompanyServiceImpl();
        ResultDTO resultDTO= companyService.update(companyVO);
//        放回值给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
